import logging

import pytest

from resource.pom.keyboard import Keyboard
from resource.pom.memorandum import Memorandum


class Test:
    app = Memorandum
    keyboard = Keyboard

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('预置条件.清除测试数据')
        device.hdc_shell('rm -rf /data/app/el2/100/database/com.ohos.note/default/rdb/note.db')
        device.wait(2)
        logging.info('步骤1.进入桌面-备忘录应用，多次点击右上角“+”新建笔记')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        for i in range(3):
            device.click(*self.app.add_note)
            device.wait(1)
            device.go_back()
            device.wait(1)
        logging.info('预期结果1.多次新建并编辑笔记保存成功，各功能正常')
        device.refresh_layout()
        new_notes = device.get_elements_by_text('标题')
        assert len(new_notes) == 3, '新建了3条笔记，只获取到{}条'.format(len(new_notes))